package com.yunji.web.storage;

import com.github.pagehelper.page.PageMethod;
import com.yunji.aggregate.model.dto.stock.StorageRecordsParam;
import com.yunji.aggregate.model.vo.stock.StorageRecordsStatisticsVO;
import com.yunji.aggregate.service.StockAggregateService;
import com.yunji.common.base.BaseController;
import com.yunji.common.base.response.Response;
import com.yunji.common.base.response.ResponseHelper;
import com.yunji.common.utils.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @Project: yunji-coffee
 * @Package: com.yunji.web.storage
 * @Title: StorageRecordsController
 * <p>
 * History:
 * Date                     Version     Author          Summary
 * ============================================================
 * 2024-08-17 10:36:41      V1.0        HuaAo       新建类
 */
@Api(tags = "管理端-库存流水")
@RestController
@RequestMapping("storage/records")
public class StorageRecordsController extends BaseController {

    @Resource
    StockAggregateService aggregateService;

    /**
     * @param param
     * @Title export
     * @Desc 导出库存流水
     * @Date 2024-10-10 15:05:36.748
     */
    @ApiOperation("导出库存流水")
    @PostMapping("/export")
//    @PreAuthorize("@ss.hasPermi('inventory:flow:export')")
    public void export(StorageRecordsParam param) {
        List<StorageRecordsStatisticsVO> list = aggregateService.searchRecordsList(param);
        ExcelUtil<StorageRecordsStatisticsVO> util = new ExcelUtil<>(StorageRecordsStatisticsVO.class);
        util.exportExcel(response, list, "库存流水数据");
    }

    /**
     * 库存流水记录列表
     *
     * @param param
     * @return
     */
    @ApiOperation("库存流水记录列表")
    @PostMapping("/list")
    public Response<List<StorageRecordsStatisticsVO>> list(@RequestBody @Valid StorageRecordsParam param) {
        PageMethod.startPage(param.getPageNum(), param.getPageSize());
        List<StorageRecordsStatisticsVO> list = aggregateService.searchRecordsList(param);
        return ResponseHelper.successWithPage(list);
    }

    /*-----------------------------------------------搜索栏---------------------------------------------*/

    @ApiOperation("商品名称匹配搜索")
    @PostMapping("/searchProductName")
    public Response<List<String>> searchProductName(@RequestBody StorageRecordsParam param) {
        return ResponseHelper.successWithPage(aggregateService.searchProductName(param));
    }

}